package training;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_7_22_Training {
    //删除子数组的最大得分
    public int maximumUniqueSubarray(int[] nums) {
        int max=0;
        int sum=0;
        int j=0;
        Set<Integer> set = new HashSet<>();
        for(int i=0;i<nums.length;++i){
            while(j<i && set.contains(nums[i])){
                set.remove(nums[j]);
                sum-=nums[j];
                j++;
            }
            set.add(nums[i]);
            sum+=nums[i];
            max=Math.max(max,sum);
        }
        return max;
    }
}
